<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>成交记录</title>

	</head>
	<body onload="init();">
		<div id="cnt">
			<input type="text" id="msg" />
			<input type="text" v-model="key"/><button @click="save">处理</button>
            <div style="display: flex;">
			<table>
				<tr style="background: #ccc;font-weight: bolder;">
					<td>名称</td>
					<td>持仓数</td>
					<td>成交价</td>
					<td>成交类型</td>
					<td>成交日期</td>
					<td>最低卖出价</td>
				</tr>
				<tr v-for="(item,idx) in buyList" :key="idx">
					<td>{{item.name}}</td>
					
					<td style="text-align: right;">{{item.num}}</td>

					<td style="text-align: right;">{{item.price}}</td>
					<td style="color:red;">{{item.deal}}</td>
					<td>{{item.date}}</td>
					<td style="color:red;text-align: right;" >{{item.sellPrice}}</td>

				</tr>
			</table>
			
			<table style="margin-left : 10px;">
				<tr style="background: #ccc;font-weight: bolder;">
					<td>名称</td>
					<td>持仓数</td>
					<td>成交价</td>
					<td>成交类型</td>
					<td>成交日期</td>
					
				</tr>
				<tr v-for="(item,idx) in sellList" :key="idx">
					<td>{{item.name}}</td>
					
					<td>{{item.num}}</td>
			
					<td>{{item.price}}</td>
					<td style="color:green;">{{item.deal}}</td>
					<td>{{item.date}}</td>
			
				</tr>
			</table>
			</div>
		</div>
	</body>
</html>
<script src="js/vue.min.js"></script>

<script>
	var app

	function init() {
		app = new Vue({
			el: "#cnt",
			mixins: [],
			data: function() {
				return {
					buyList: [],
					sellList:[],
					key:"",
				}
			},
			methods: {
				save() {
					let rows = document.getElementById("msg").value.split("\t详情");
					rows = rows.reverse();
					this.buyList=[];
					this.sellList=[];
					rows.forEach(item => {
						let itemArr = item.split("\t");
						
						if (itemArr[1] == "证券买入") {
							let obj = {};
							let nameCode = itemArr[0].split(" ");
							obj.name = nameCode[1];
							obj.code = nameCode[2];
							obj.num = itemArr[2];
							obj.price = itemArr[3];
							obj.deal = itemArr[1];
							obj.date = itemArr[6];
							let sellFee = (obj.num*obj.price+10+(obj.num*obj.price)*0.001)/obj.num;
							obj.sellPrice = sellFee.toFixed(2);
							this.key ==""?this.buyList.push(obj):null;
							this.key ==obj.name?this.buyList.push(obj):null;
							
						}
						if (itemArr[1] == "证券卖出") {
							let obj = {};
							let nameCode = itemArr[0].split(" ");
							obj.name = nameCode[1];
							obj.code = nameCode[2];
							obj.num = itemArr[2];
							obj.price = itemArr[3];
							obj.deal = itemArr[1];
							obj.date = itemArr[6];
							this.key ==""?this.sellList.push(obj):null;
							this.key ==obj.name?this.sellList.push(obj):null;
							
						}
					});
				
				}
			}
		});
	};
</script>
